package com.dealin.dealinlibs.tool;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;

/**
 * Created by lenovo on 2016/7/13.
 */
public class ImageTool {
    public Bitmap bitmap;
    public Canvas canvas;
    public Paint paint;
    public ImageTool() {
        paint = new Paint();
    }

    public void setPaint(Paint paint) {
        this.paint = paint;
        paint.setAntiAlias(true);
        paint.setDither(true);
    }

    public Bitmap drawRoundRect(int w, int h, int rad) {
        bitmap=Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
        canvas=new Canvas(bitmap);
        RectF rectF=new RectF(0,0,w,h);
        canvas.drawRoundRect(rectF,rad,rad,paint);
        return bitmap;
    }
    public Bitmap drawRect(int w, int h) {
        bitmap=Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
        canvas=new Canvas(bitmap);
        RectF rectF=new RectF(0,0,w,h);
        canvas.drawRect(rectF,paint);
        return bitmap;
    }

    public Bitmap draw6Polygon(int w,int h) {
        bitmap=Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
        canvas=new Canvas(bitmap);
        Path path=new Path();
        path.lineTo(w/4,0);
        path.lineTo(0,h/2);
        path.lineTo(w / 4, h);
        path.lineTo(3 * (w / 4), h);
        path.lineTo(w, h / 2);
        path.lineTo(3 * (w / 4), 0);
        path.lineTo(w/4,0);
        path.close();
        canvas.drawPath(path, paint);
        return bitmap;
    }

    public Bitmap drawGroupPropertyShape(int w, int h) {
        bitmap=Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
        canvas=new Canvas(bitmap);
        Path path=new Path();
        path.lineTo(w / 2, 0);

        path.lineTo(w / 6, 0);

        path.lineTo(0, h / 2);

        path.lineTo(w/6, h);

        path.lineTo(w / 2, h);
        path.lineTo(w/2,0);
        path.close();
        canvas.drawPath(path, paint);
        RectF rectF=new RectF(w/2-10,0,w,h);
        canvas.drawRect(rectF,paint);
        return bitmap;
    }


}
